package com.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dao.ProductDao;
import com.pojo.Product;
import com.pojo.ProductOrder;
import com.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author lifeng
 * @create 2022-11-28 23:34
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductDao, Product> implements ProductService {

    @Autowired
    private ProductDao productDao;

    /**
     * 根据类型查找商品集合并分页
     * @param page
     * @param limit
     * @return
     */
    @Override
    public IPage<Product> selectPageByTypeId(Long page, Long limit, Long productTypeId) {

        //创建page对象
        Page<Product> productPage = new Page<Product>(page,limit);

        //构建额外条件
        QueryWrapper<Product> wrapper = new QueryWrapper<>();
        //根据type_id相等的情况下进行分页
        wrapper.eq("type_id",productTypeId);

        IPage<Product> productPage1 = productDao.selectPage(productPage, wrapper);


        return productPage1;
    }

}
